package com.jscloud.bigdata.hbase.mr3;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.tool.BulkLoadHFiles;

/**
 *  加载HFile文件到hbase表中
 *
 * * 方式一：代码加载
 */
public class LoadData {
        public static void main(String[] args) throws Exception {
                Configuration configuration = HBaseConfiguration.create();
                configuration.set("hbase.zookeeper.quorum", "bigdata01,bigdata02,bigdata03");
                // 获取数据库连接
                Connection connection = ConnectionFactory.createConnection(configuration);
                // 获取表的管理器对象
                Admin admin = connection.getAdmin();
                // 获取table对象
                TableName tableName = TableName.valueOf("myuser2");
                Table table = connection.getTable(tableName);
                // 构建BulkLoadHFiles加载HFile文件 hbase2.0 api
                BulkLoadHFiles load = BulkLoadHFiles.create(configuration);
                load.bulkLoad(tableName, new Path("hdfs://bigdata01:8020/hbase/out_hfile"));
        }

}